<?php

namespace app\shopapi\controller;

use app\admin\model\shop\Category;
use app\common\controller\Shopapi;
use app\shopapi\model\pay\ShopInfeed;
use app\shopapi\model\ShopAdmin;
use app\shopapi\model\ShopBills;
use app\shopapi\model\ShopBillsExport;
use app\shopapi\model\ShopBillsStat;
use app\shopapi\model\ShopUser;
use think\Log;

/**
 * 店铺账单接口
 */
class Bills extends Shopapi
{
    protected $noNeedRight = '*';


    //账单流水
    public function stat()
    {

        $stat_model = new ShopBillsStat();

        $lists = $stat_model->getlist($this->shopauth->shop_id);

        $this->success('',$lists);
    }


    //筛选账单流水
    public function lists()
    {
        $params = input();
        $bills_model = new ShopBills();

        $lists = $bills_model->getlist($this->shopauth->shop_id,$params);

        $this->success('',$lists);
    }

    //账单流水
    public function page()
    {

        $bills_model = new ShopBills();

        $lists = $bills_model->pages($this->shopauth->shop_id);

        $this->success('',$lists);
    }

    //账单详情
    public function detail()
    {
        $bills_id = input('bills_id',0);

        $bills_model = new ShopBills();

        $lists = $bills_model->detail($bills_id);

        $this->success('',$lists);
    }


    //实时账单
    public function realtime()
    {
        $bills_model = new ShopBills();

        $lists = $bills_model->getRealtimeList($this->shopauth->shop_id);

        $this->success('',$lists);
    }


    //导出
    public function export()
    {
        try {
            $params = input();
            $bills_model = new ShopBills();

            $lists = $bills_model->export($this->shopauth->shop_id,$params);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('',$lists);
    }

    //下载中心
    public function exportList()
    {
        $list = ShopBillsExport::order('createtime desc')->select();
        $this->success('',$list);
    }

    //退款
    public function refund()
    {

        try {
            $bills_id = input('bills_id',0);
            $bills_model = new ShopBills();

            $lists = $bills_model->refund($this->shopauth->shop_id,$bills_id);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('',$lists);
    }
}